package com.api.shopapi.service.impl;

import com.api.shopapi.entity.ArticleClass;
import com.api.shopapi.entity.TrainClass;
import com.api.shopapi.entity.dto.ArticleClassDTO;
import com.api.shopapi.entity.dto.TrainClassDTO;
import com.api.shopapi.mapper.TrainClassMapper;
import com.api.shopapi.service.TrainClassService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("TrainClassServiceImplOne")
public class TrainClassServiceImplOne implements TrainClassService {

    @Autowired
    private TrainClassMapper trainClassMapper;

    @Override
    public
    int insert(TrainClass trainClass){
        return trainClassMapper.insert(trainClass);
    }
    @Override
    public
    int update(TrainClass trainClass){
        return trainClassMapper.update(trainClass);
    }
    @Override
    public
    TrainClass getByTrainClassCode(String trainClassCode){
        return trainClassMapper.getByTrainClassCode(trainClassCode);
    }
    @Override
    public
    List<TrainClass> getListByParentTrainClassCode(String parentTrainClassCode){
        return trainClassMapper.getListByParentTrainClassCode(parentTrainClassCode);
    }


    @Override
    public
    List<TrainClassDTO> getFirstClassList(String governmentCode){
        return trainClassMapper.getFirstClassList(governmentCode);
    }


    @Override
    public
    List<TrainClassDTO> getListByGovernmentCode(String governmentCode) {
        List<TrainClassDTO> articleClassDTOList = trainClassMapper.getFirstClassList(governmentCode);
        for (TrainClassDTO articleClassDTO : articleClassDTOList) {
            List<TrainClass> articleClassList = trainClassMapper.getAllListByParentTrainClassCode(articleClassDTO.getTrainClassCode());
            articleClassDTO.setListTrainClass(articleClassList);
        }
        return articleClassDTOList;
    }
    @Override
    public
    PageInfo<TrainClassDTO> getPage(int pageIndex, int pageSize, String name, String governmentCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<TrainClassDTO> articleClassDTOList = trainClassMapper.getPage(name, governmentCode);
        for (TrainClassDTO articleClassDTO : articleClassDTOList) {
            List<TrainClass> articleClassList = trainClassMapper.getAllListByParentTrainClassCode(articleClassDTO.getTrainClassCode());
            articleClassDTO.setListTrainClass(articleClassList);
        }
        return new PageInfo<>(articleClassDTOList);
    }


}
